<?php
namespace jy_city;
defined('BY_JYA') or exit('error');
/*
	分销插件工具类
*/
class model extends \plugin{
	
	public function out_times($store_id,$post=array()) {
		$store=pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$store_id));
		$store['onlinetime']=json_decode($store['onlinetime'],true);
		$store['out_pay']=$post['out_pay']?:$store['out_pay'];
		$store['out_pay']=price($store['out_pay']);
		//配送时间
		$days = array(
				0=>date("m-d",time("day")),
				1=>date("m-d",strtotime("+1 day")),
				2=>date("m-d",strtotime("+2 day")), 
				3=>date("m-d",strtotime("+3 day")), 
				4=>date("m-d",strtotime("+4 day")),
				5=>date("m-d",strtotime("+5 day")),
				6=>date("m-d",strtotime("+6 day")),
		);
		$totaytime = strtotime(date('Y-m-d'));
		//配送时间段
		$lasttimebox=0;
		$timestamp = array();
		$daytime=date('Y-m-d');
		$times[] = array(
				'id' => 1,
				'lasth' => 11,
				'fee' => 0,
				'timev' =>'上午(08点~12点)',
		);
		$times[] = array(
				'id' => 2,
				'lasth' => 18,
				'fee' => 0,
				'timev' =>'下午(12点~16点)',
		);
		$times[] = array(
				'id' => 3,
				'lasth' => 22,
				'fee' => 0,
				'timev' =>'晚上(16点~22点)',
		);
		$data = array(
			'days' => $days,
			'times' => $times,
			'timestamp' => $timestamp,
			'updatetime' => strtotime(date('Y-m-d')) + 86400,
			'reserve' => 0,
			'lasttimebox' => $lasttimebox,
		);
		return $data;
	}
	public function payresult($order,$payresult=array()){
		pdo_update('jy_weishop_table_order',array('status'=>'1','pay'=>$payresult['fee']),array('id'=>$order['id']));
		$postdata = array(
						'first' => array(
							'value' => '您好，您有新的预约',
							'color' => '#990000'
						),
						'keyword1' => array(
							'value' => $order['day'],
							'color' => '#ff510'
						),
						'keyword2' => array(
							'value' => $order['title'],
							'color' => '#ff510'
						),
						'keyword3' => array(
							'value' => $order['username'],
							'color' => '#ff510'
						),
						'keyword4' => array(
							'value' => $order['mobile'],
							'color' => '#ff510'
						),
						'keyword5' => array(
							'value' => $order['address'],
							'color' => '#ff510'
						),
						'remark' => array(
							'value' => '请尽快受理，谢谢！',
							'color' => '#ff510'
						),							
		);
		$template_id=cfc('account')->get_tpl_template_id('OPENTM415037654','新预约订单通知');
		$url=custom_url('jy_merch/manage.index/',true);
		$message_tpl=$this->plugin_setting('message_tpl');
		if($message_tpl['isnew']==1){
			if($worker['mid']){
				cfc('account')->sendTplNotice($worker['mid'],$template_id,$postdata,$url);
			}else{
				cfc('account')->sendTplNotice($serve['managerid'],$template_id,$postdata,$url);
			}
		}
	}
	public function days() {
		//日期
		$data=array();
		$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
		$days=$days>0?$days:7;
		for($i=0;$i<$days;$i++){
			$data[]=array('ymd'=>date("Y-m-d",strtotime("+".$i." day")),'riqi'=>date("m-d",strtotime("+".$i." day")),'xinq'=>"星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+".$i." day"))))],'isshow'=>1);
		}
		return $data;
	}
}